package com.synchornize;

import java.util.Scanner;

public class Test_1 {
    public static void main(String[] args) {
        A a = new A();
        B b = new B(a);
        a.start();
        b.start();

//        for(int i=0;i<80;i++){
//            System.out.println("我在学java"+i);
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        }
    }
}


class A extends Thread{
    private boolean loop=true;

    public boolean isLoop() {
        return loop;
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }

    @Override
    public void run() {
        super.run();
        while(loop){
            System.out.println("我吃饭");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}

class B extends Thread{
    private A a;
    private Scanner scanner=new Scanner(System.in);
    public B(A a){
        this.a=a;
    }
    @Override
    public void run() {
        super.run();
        String str=null;
        while(true){
            System.out.println("请输入okkkkkkkkkkkk:");
            try {
                str=scanner.next();
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(str.equals("ok")){
                a.setLoop(false);
                System.out.println("输入完成了");
                break;
            }
        }
    }
}